<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="com.alpha.bom.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Exam Responses Report</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/displaytag.css"/>

</head>
<body>

	<div id="header"><%@ include file="Header.jsp"%></div>
	<div id="content">
	<c:choose>
		<c:when test="${not empty user}">
			<div id="navbar"><%@ include file="NavigationBar.jsp"%></div>
			<div id="main">
		</c:when>
		<c:otherwise>
			<div id="alluser">
		</c:otherwise>
	</c:choose>
		<c:set var="user" value="${sessionScope.user }"/>
		<c:set var="exam_response" value="${requestScope.exam_response }"/>
		<c:if test="${empty exam_response}" >
			<c:redirect url="LoginServlet"></c:redirect>
		</c:if>
		<c:set var="message" value="${param.message}"></c:set>
		<c:set var="error" value="${param.error}"></c:set>
		<c:set var="success" value="${param.success}"></c:set>
		
		<div class="box">
			<div class="box-header well">
				<h2><i class="icon-list-alt"></i> Exam Information</h2>
				<div class="box-icon">
					<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
				</div>
			</div>
			
			<div class="box-content">
				<form class="form-horizontal">
					
					<fieldset>
						<div class="control-group">
							<label class="control-label">Exam Details:</label>
							<br><br>
							<label class="control-label">Exam ID</label>
							<div class="controls">
								<div class="alert alert-info" style="width:230px;">${exam_response.getExam().getExamId()}</div>
							</div>
							<label class="control-label">Exam Name</label>
							<div class="controls">
								<div class="alert alert-info" style="width:230px;">${exam_response.getExam().getExamName()}</div>
							</div>
							<c:if test="${(not empty user) and (not empty exam_response.student ) }">
								<br>
								<label class="control-label">Examinee Details:</label>
								<br><br>
								<label class="control-label">Examinee ID</label>
								<div class="controls">
									<div class="alert alert-info" style="width:230px;">${exam_response.getStudent().getUserId()}</div>
								</div>
								<label class="control-label">Examinee Name</label>
								<div class="controls">
									<div class="alert alert-info" style="width:230px;">${exam_response.getStudent().getLastName()}, ${exam_response.getStudent().getFirstName()}</div>
								</div>
							</c:if>
							<label class="control-label">Score</label>
							<div class="controls">
								<div class="alert alert-info" style="width:230px;">${exam_response.computeScore()}</div>
							</div>
						</div>
					</fieldset>	  
				</form>
			</div>
		</div>
		
		<div class="box">
			<div class="box-header well">
				<h2><i class="icon-edit"></i> Response Details</h2>
				<div class="box-icon">
					<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
				</div>
			</div>
			<div class="box-content">
				<display:table name="${exam_response.getExam().getQuestions()}" id="question" export="true" class="table table-striped table-bordered bootstrap-datatable datatable">
						<display:column title="Question" media="html">${question.getQuestion()}</display:column>
						<display:column title="Question" media="pdf excel csv xml rtf">${fn:replace(fn:replace(question.getQuestion(),"&nbsp"," "),"<br>","")}</display:column>
						<display:column title="Answer">${exam_response.getAnswers().get(question).getAnswer()}</display:column>
						<display:column title="Correct Answer">${question.getCorrectAnswer().getAnswer()}</display:column>
						
						<display:caption media="pdf excel csv xml rtf">${exam_response.getStudent().getLastName()}, ${exam_response.getStudent().getFirstName()}'s Exam Response</display:caption>
						
						<display:setProperty name="export.pdf" value="true"/>
						<display:setProperty name="export.pdf.filename" value="export.pdf"/>
						<display:setProperty name="export.excel.filename" value="export.xls"/>
						<display:setProperty name="export.csv.filename" value="export.csv"/>
						<display:setProperty name="export.xml.filename" value="export.xml"/>
						<display:setProperty name="export.rtf.filename" value="export.rtf"/>
					</display:table>
				
			</div>
		</div>
		
	<c:if test="${empty user}">
	<center>
		<br/>
		<a class="btn" href="PracticeExamServlet"><i class="icon-edit"></i> Back to Practice Exams Page</a>  
		<a class="btn" href="Login.jsp"><i class="icon-user"></i> Back to Login Page</a><br/>
	</center>
	</c:if>
	
	<c:choose>
	<c:when test="${not empty message}">
	<script>$(document).ready(function() {$.noty({ text: '${message}', type: 'information', layout: 'top'});});</script>
	</c:when>
	<c:when test="${not empty error}">
	<script>$(document).ready(function() {$.noty({ text: '${error}',type: 'error',layout: 'top'});});</script>
	</c:when>
	<c:when test="${not empty success}">
	<script>$(document).ready(function() {$.noty({text: '${success}',type: 'success',layout: 'top'});});</script>
	</c:when>
	</c:choose>
	
	<c:if test="${not empty user}">
	</div>
	</c:if>
	
	</div>
	
<script>
	$(document).ready(function() {
		$("span[class*='export']").parent().each(function() {
			this.href = this.href.replace("StudentResponse.jsp", "StudentResponseServlet");
		});
	});
</script>
</body>
</html>